
using System;
using Cairo;

namespace finlasku
{
	
	
	public class InvoicePrintOperation : Gtk.PrintOperation
	{
		private Invoice _invoice;
		
		public InvoicePrintOperation()
		{
			NPages = 1;
			//_invoice = invoice;
		}
		
		protected override void OnBeginPrint (Gtk.PrintContext context)
        {
        	base.OnBeginPrint(context);
		}
		
		protected override void OnDrawPage (Gtk.PrintContext context, int page_nr)
        {
			//just drawing something for sake of testing
        	base.OnDrawPage (context, page_nr);
        
        	Context cr = context.CairoContext;
			
			//creating instance from Image Surface then loading that logo to Gtk.Context and painting that.
			ImageSurface logo = new ImageSurface("/home/henri/warsow.png");
			cr.SetSourceSurface(logo, 50, 50);
			cr.Paint();
                        
        	for ( int i = 1; i <= 10; i++) {
         		cr.SetSourceRGBA(0, 0, 1, i*0.1);
                cr.Rectangle(50*i, 20, 40, 40);
                cr.Fill();  
         	}
			
			//creating some text
			cr.SelectFontFace("serif", FontSlant.Normal, FontWeight.Bold);
			cr.SetFontSize(25.0);
			cr.MoveTo(10, 50);
			cr.ShowText(_invoice.Title);
			
			foreach(InvoiceRow row in _invoice.Rows)
			{
				cr.MoveTo(10, 50 + row.Id * 5);
				cr.ShowText(row.ItemName);
			}
			

         }
                
         protected override void OnEndPrint (Gtk.PrintContext context)
         {
         	base.OnEndPrint (context);
         	context.Dispose ();
         }
                
         protected override void OnRequestPageSetup (Gtk.PrintContext context, int page_nr, Gtk.PageSetup setup)
         {
         	base.OnRequestPageSetup (context, page_nr, setup);
         }
	}
}
